package li.webqq.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import li.http.Response;
import li.webqq.model.Group;
import li.webqq.util.JsonUtil;
import li.webqq.util.MapUtil;

/**
 * @author 明伟
 */
public class GetGroupNameListMask2Response extends Response {
    private List<Group> groups;

    public List<Group> getGroups() {
        if (null == this.groups) {
            Map map = (Map) JsonUtil.fromJson(super.getBody());
            Map result = (Map) map.get("result");
            this.groups = getGroups(result);
        }
        return this.groups;
    }

    private List<Group> getGroups(Map result) {
        List<Map> gnamelist = (List<Map>) result.get("gnamelist");
        if (null == gnamelist || gnamelist.isEmpty()) {
            return null;
        }
        List<Group> groups = new ArrayList<Group>();
        for (Map gname : gnamelist) {
            groups.add(MapUtil.parse(Group.class, gname));
        }
        Map gname = gnamelist.get(0);
        return groups;
    }
}